package com.service.impl;

import com.bean.entity.StudentComment;
import com.bean.pojo.PageAssistant;
import com.bean.vo.StudentCommentVo;
import com.dao.StudentCommentMapper;
import com.service.StudentCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * User: 刘文雄
 * Date:2022/3/30 15:41
 * 学生评价表
 */
@Service
public class StudentCommentServiceImpl implements StudentCommentService {

    @Autowired
    private StudentCommentMapper studentCommentMapper;
    @Override
    public int save(StudentComment t) throws Exception {
        int insert = studentCommentMapper.insert(t);
        if (insert==1) return 1;
        throw new Exception("新增学生评价信息失败");
    }
    @Override
    public int remove(StudentComment t) throws Exception {
        int delete = studentCommentMapper.delete(t);
        if (delete==1) return 1;
        throw new Exception("删除学生评价信息失败");
    }
    @Override
    public int modify(StudentComment t) throws Exception {
        int update = studentCommentMapper.update(t);
        if (update==1) return 1;
        throw new Exception("修改学生评价信息失败");
    }
    @Override
    public StudentCommentVo unique(StudentComment t) throws Exception {
        List<StudentCommentVo> studentCommentVoList = studentCommentMapper.select(t);
        if (studentCommentVoList.size() !=1)
            throw new Exception("没有相关信息");
        return studentCommentVoList.get(0);
    }
    @Override
    public List<StudentCommentVo> query(StudentComment t) {
        List<StudentCommentVo> studentCommentVoList = studentCommentMapper.select(t);
        return studentCommentVoList;
    }
    @Override
    public PageAssistant<StudentCommentVo> queryByPage(Map<String, Object> map, PageAssistant<StudentCommentVo> pa) {

        //设置并查询总记录数
        pa.setCount(studentCommentMapper.selectCount(map));
        //添加分页参数
        map.put("startCode", pa.getStartCode());
        map.put("pageSize", pa.getPageSize());

        //查询并设置页面内容
        pa.setItems(studentCommentMapper.selectByPage(map));
        return pa;
    }
}
